package com.kfm.pm.linkedList;

import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDemo {

    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList(); //
        linkedList.add("蜜雪冰城");
        linkedList.add("瑞幸");
        linkedList.add("星巴克");
        linkedList.addFirst("喜茶");  //  实现自 Deque
        linkedList.addLast("茶百道"); //
        // 遍历
//        Iterator iterator = linkedList.iterator();
//        while (iterator.hasNext()) {
//            System.out.println(iterator.next());
//        }
//        linkedList.removeFirst();
//        linkedList.removeLast();
//        linkedList.remove(1);
        linkedList.remove("星巴克");
        System.out.println(linkedList.get(1));
//        linkedList.forEach(object -> System.out.println(object));
//        for ( int i = 0; i < linkedList.size(); i ++) {
//            System.out.println(linkedList.get(i));
//        }
        for (Object ob : linkedList) {
            System.out.println(ob);
        }
        System.out.println(linkedList.offer("一点点")); // add
        System.out.println(linkedList.peek()); // 第一个元素
//        System.out.println(linkedList.pop()); // removeFirst
//        System.out.println(linkedList.poll()); // 删除头
        System.out.println();
        linkedList.push("七分甜"); // addFirst
        System.out.println(linkedList.contains("喜茶"));
        System.out.println(linkedList.indexOf("七分甜"));


//        linkedList.add(0, "喜茶");

    }
}
